home *** CD-ROM | disk | FTP | other *** search
/ Zoom 2 / Zoom - Release 2 (1996)(Active Software)[!].iso / programming / amigae / xpk25edev / source / xpkrev.e < prev    next >
Encoding:
Text File  |  1996-01-19  |  12.1 KB  |  419 lines

  1. -> preprocess (and use) the version macros (VERSION_INFO and VERSION_STRING)
  2. -> however, these are not used here, so it's left commented
  3. -> OPT PREPROCESS
  4.  
  5. -> implements a full Commodore-Amiga compliant versionstring.
  6.  
  7. /*
  8. **
  9. ** name          : xpkrev.e
  10. **
  11. ** original name : Bumpee.e (included in Bumpee archive)
  12. **
  13. ** Bumpee 1.44 © 1995 by Leon Woestenberg (leon@stack.urc.tue.nl)
  14. ** (found in aminet:dev/e/ directory or in this package.)
  15. **
  16. ** xpkrev is a modified Bumpee to use with xpk sublibraries
  17. ** for easier version/revision-control. No major change though.
  18. **
  19. ** Feel free to alter this source to suit your needs under the
  20. ** conditions in Bumpee.doc
  21. **
  22. ** The changes are:
  23. **
  24. ** - will for example crete LIB_NAME 'xpkNONE.library'
  25. **   from source name 'none.e'. 'none' converted to upper case.
  26. ** - some defines to build other define strings
  27. **   (define's are ugly aren't they. I sould want string constants instead.
  28. ** - modes, info - versions (BUMPINFO=INFO/S,BUMPMODES=MODES/S)
  29. ** - new datestring inspired by Commodore libraries versionstrings
  30. **   (old one still in  'datestring', new in 'datestr')
  31. ** - changed filename extension to avoid confusion (_xpkrev.e)
  32. ** - moved errors to exception handler instead of IF,ELSE,ENDIF
  33. ** - some error messages slightly changed
  34. ** - added a few error messages (ERR_BUMP_DELETE, ERR_OPEN_BUMP_WRITE)
  35. ** - added comments, som initialisation values, type LONG in DEF
  36. **
  37. **
  38. ** Read the documentation for Bumpee for usage, etc, etc.
  39. **
  40. **
  41. ** Thanks to Leon for releasing this program with it's source!
  42. **
  43. **
  44. ** /Torgil Svensson (snorq@lysator.liu.se) 
  45. **
  46. ** (orig. bumpee used to bump this program)
  47. ** 
  48. */
  49.  
  50. MODULE '*xpkrev_rev'
  51.  
  52. MODULE 'dos/dos','dos/rdargs','dos/datetime','intuition/intuition'
  53.  
  54.  
  55. ENUM ERR_NONE=0,
  56.      ERR_ARGS,
  57.      ERR_NO_SOURCE,
  58.      ERR_LAST_COMPILED,
  59.      ERR_NO_BUMPFILE,
  60.      ERR_BUMP_DELETE,
  61.      ERR_OPEN_BUMP_WRITE
  62.  
  63.  
  64. RAISE ERR_ARGS IF ReadArgs() = NIL
  65.  
  66.  
  67. PROC main() HANDLE
  68.  
  69.   -> args
  70.   DEF readargs:PTR TO rdargs,
  71.       args          =NIL   :PTR TO LONG,
  72.       exefile[256]         :STRING,      -> NAME
  73.       forcebump     =FALSE :LONG,        -> CREATE=FORCE
  74.       bumpversion   =FALSE :LONG,        -> BUMPVERSION=VERSION
  75.       donotcompile  =FALSE :LONG,        -> DONOTCOMPILE
  76.       ecpath[256]          :STRING,      -> ECFILEPATH
  77.       bumpinfo      =FALSE :LONG,        -> BUMPINFO=INFO
  78.       bumpmodes     =FALSE :LONG         -> BUMPMODES=MODES
  79.  
  80.  
  81.   -> file stuff
  82.   DEF sourcefile[256]      :STRING,      -> NAME.e
  83.       modfile[256]         :STRING,      -> NAME.m
  84.       bumpfile[256]        :STRING,      -> NAME_xpkrev.e
  85.       bumpfh          =NIL :LONG,        -> bump filehandle
  86.       exefh           =NIL :LONG,        -> used to compare dates
  87.  
  88.       bumpfib = NIL :PTR TO fileinfoblock, -> used to compare dates
  89.       exefib  = NIL :PTR TO fileinfoblock, -> used to compare dates
  90.  
  91.       bumpcontents[1024] :STRING   -> r/w-buffer for bumpfile (Fputs/Fgets)
  92.  
  93.  
  94.   -> dos date vars
  95.   DEF datetime:datetime,
  96.       datestring[LEN_DATSTRING]:STRING
  97.  
  98.  
  99.   -> values changed each bump
  100.   DEF name[256]     :STRING,
  101.       day       =0  :LONG,
  102.       month     =0  :LONG,
  103.       year      =0  :LONG,
  104.       version   =1  :LONG,
  105.       revision  =0  :LONG,
  106.  
  107.       info_version  =0      :LONG,  -> added for xpkrev
  108.       modes_version =0      :LONG,  -> added for xpkrev
  109.       datestr[LEN_DATSTRING]:STRING -> added for xpkrev
  110.  
  111.  
  112.   -> misc
  113.   DEF bumpflag=FALSE      :LONG,  -> ...
  114.       commandstring[256]  :STRING -> cmd-string for execute (compile)
  115.  
  116.  
  117.  
  118.  
  119. /*---------------------------  read args  ---------------------------*/
  120.  
  121.  
  122.   GetProgramName(exefile,256)
  123.   readargs:=ReadArgs('NAME/A,'                 +
  124.                      'CREATE=FORCE/S,'         +
  125.                      'BUMPVERSION=VERSION/S,'  +
  126.                      'DONOTCOMPILE/S,'         +
  127.                      'ECFILEPATH/K,'           +
  128.                      'BUMPINFO=INFO/S,'        +
  129.                      'BUMPMODES=MODES/S'     ,
  130.        args:=[NIL,FALSE,FALSE,FALSE,'EC',FALSE,FALSE],NIL)
  131.   StrCopy(exefile,args[0])
  132.   forcebump:=args[1]
  133.   bumpversion:=args[2]
  134.   donotcompile:=args[3]
  135.   StrCopy(ecpath,args[4])
  136.   bumpinfo:=args[5]
  137.   bumpmodes:=args[6]
  138.   FreeArgs(readargs)
  139.  
  140.  
  141.  
  142.  
  143. /*---------------------  file names (copyright) ---------------------*/
  144.  
  145.  
  146.   IF StrCmp(exefile+EstrLen(exefile)-2,'.e',2)
  147.     MidStr(exefile,exefile,0,EstrLen(exefile)-2)
  148.   ENDIF
  149.   StrCopy(sourcefile,exefile)
  150.   StrAdd(sourcefile,'.e')
  151.   StrCopy(modfile,exefile)
  152.   StrAdd(modfile,'.m')
  153.   StrCopy(bumpfile,exefile)
  154.   StrAdd(bumpfile,'_xpkrev.e')
  155.  
  156.   -> print out a copyright notice with actual version information
  157.   PrintF('xpkrev \d.\d Changed for use with xpk sublibraries by Torgil Svensson.\n\n'+
  158.          'Original program: Bumpee 1.44 (6.1.95) © 1995 by Leon Woestenberg\n\n',
  159.          VERSION,REVISION)
  160.  
  161.   -> look for source
  162.   IF FileLength(sourcefile) = 0 THEN Raise(ERR_NO_SOURCE)
  163.  
  164.  
  165.  
  166.  
  167. /*--------------------------  datestring  ---------------------------*/
  168.  
  169.  
  170.   -> create dos datestring
  171.   datetime.format:=FORMAT_CDN
  172.   datetime.flags:=0
  173.   datetime.strday:=NIL
  174.   datetime.strdate:=datestring
  175.   datetime.strtime:=NIL
  176.   DateStamp(datetime)
  177.   DateToStr(datetime)
  178.   day:=Val(datestring)
  179.   month:=Val(datestring+3)
  180.   year:=Val(datestring+6)
  181.  
  182.   -> create new datestr.
  183.   IF year < 78 THEN StrCopy(datestr,'20',2) ELSE StrCopy(datestr,'19',2)
  184.   StrAdd(datestr,datestring+6,2)  -> year
  185.   StrAdd(datestr,datestring+2,4)  -> -month-
  186.   StrAdd(datestr,datestring,2)    -> day
  187.  
  188.  
  189.  
  190.  
  191. /*------------------------  bump versions  --------------------------*/
  192.  
  193.  
  194.   IF bumpfh:=Open(bumpfile,MODE_OLDFILE)
  195.  
  196.  
  197. /*
  198. ** set bumpflag if exefile newer than bumpfile (dates)
  199. ** else raise exception
  200. */
  201.  
  202.     IF forcebump
  203.       bumpflag:=TRUE
  204.     ELSE
  205.       IF bumpfib:=AllocDosObject(DOS_FIB,0)
  206.         IF ExamineFH(bumpfh,bumpfib)
  207.           IF exefh:=Open(exefile,MODE_OLDFILE)
  208.             IF exefib:=AllocDosObject(DOS_FIB,0)
  209.               IF ExamineFH(exefh,exefib)
  210.                 bumpflag:=(CompareDates(bumpfib+132,exefib+132)>0)
  211.               ENDIF
  212.               FreeDosObject(DOS_FIB,exefib)
  213.             ENDIF
  214.             Close(exefh)
  215.           ENDIF
  216.         ENDIF
  217.         FreeDosObject(DOS_FIB,bumpfib)
  218.       ENDIF
  219.     ENDIF
  220.  
  221.  
  222.     IF bumpflag = FALSE THEN Raise(ERR_LAST_COMPILED)
  223.  
  224.  
  225. /*
  226. **  read the versions from the BUMP structure
  227. **  note that MODES/INFO_VERSION must be tested before VERSION
  228. */
  229.  
  230.     WHILE Fgets(bumpfh,bumpcontents,1023)
  231.       IF InStr(bumpcontents,'BUMP')<>-1
  232.         WHILE Fgets(bumpfh,bumpcontents,1023)
  233.            EXIT InStr(bumpcontents,'ENDBUMP')<>-1
  234.            IF InStr(bumpcontents,'NAME=')<>-1
  235.              MidStr(name,bumpcontents,InStr(bumpcontents,'=')+1)
  236.              SetStr(name,StrLen(name)-1)
  237.            ELSEIF InStr(bumpcontents,'INFO_VERSION=')<>-1
  238.              info_version:=Val(bumpcontents+InStr(bumpcontents,'=')+1)
  239.            ELSEIF InStr(bumpcontents,'MODES_VERSION=')<>-1
  240.              modes_version:=Val(bumpcontents+InStr(bumpcontents,'=')+1)
  241.            ELSEIF InStr(bumpcontents,' VERSION=')<>-1
  242.              version:=Val(bumpcontents+InStr(bumpcontents,'=')+1)
  243.            ELSEIF InStr(bumpcontents,' REVISION=')<>-1
  244.              revision:=Val(bumpcontents+InStr(bumpcontents,'=')+1)
  245.            ENDIF
  246.         ENDWHILE
  247.       ENDIF
  248.       EXIT StrCmp(bumpcontents,'ENDBUMP')
  249.     ENDWHILE
  250.  
  251.  
  252. /*
  253. **  Bump version-numbers
  254. */
  255.  
  256.     IF bumpinfo
  257.       info_version  := info_version  + 1
  258.       PrintF('Bumping xpkInfo structure verision to \d\n',info_version)
  259.     ENDIF
  260.     IF bumpmodes
  261.       modes_version  := modes_version  + 1
  262.       PrintF('Bumping xpk mode descriptors verision to \d\n',modes_version)
  263.     ENDIF
  264.     IF bumpversion
  265.       version:=version+1
  266.       revision:=0
  267.       PrintF('Bumping version to \d.\d...',version,revision)
  268.     ELSE
  269.       revision:=revision+1
  270.       PrintF('Bumping revision to \d.\d...',version,revision)
  271.     ENDIF
  272.     Close(bumpfh)
  273.  
  274.   ELSE  ->  if Open(bumpfile,...) failed
  275.  
  276.  
  277. /*
  278. ** Bumpfile does not exist
  279. ** Create new bumpfile if CREATE (forcebump) option is set.
  280. */
  281.  
  282.     IF forcebump = FALSE THEN Raise(ERR_NO_BUMPFILE)
  283.     StrCopy(name,FilePart(exefile))
  284.     UpperStr(name)
  285.     bumpflag:=TRUE
  286.     PrintF('Creating bump module...')
  287.  
  288.   ENDIF
  289.  
  290.  
  291.  
  292.  
  293. /*-------------------  save/compile new bumpfile  -------------------*/
  294.  
  295.  
  296.   IF bumpflag
  297.  
  298.  
  299. /*
  300. ** (Re)write Bumpfile with new values
  301. */
  302.  
  303.     DeleteFile(bumpfile)
  304.     IF FileLength(bumpfile)<>-1 THEN Raise(ERR_BUMP_DELETE)
  305.     bumpfh:=Open(bumpfile,MODE_NEWFILE)
  306.     IF bumpfh = NIL THEN Raise(ERR_OPEN_BUMP_WRITE)
  307.  
  308.     StringF(bumpcontents,'-> xpkrev module. Do not alter this file manually.\n\n'+
  309.                          'OPT MODULE\n'+
  310.                          'OPT EXPORT\n'+
  311.                          'OPT PREPROCESS\n'+
  312.                          '\n'+
  313.                          '/*\n'+
  314.                          'BUMP\n'+
  315.                          '  NAME=\s\n'+
  316.                          '  VERSION=\d\n'+
  317.                          '  REVISION=\d\n'+
  318.                          '  INFO_VERSION=\d\n'+
  319.                          '  MODES_VERSION=\d\n'+
  320.                          'ENDBUMP\n'+
  321.                          '*/\n'+
  322.                          '\n'+
  323.                          'CONST VERSION=\d\n'+
  324.                          'CONST REVISION=\d\n'+
  325.                          'CONST INFO_VERSION=\d\n'+
  326.                          'CONST MODES_VERSION=\d\n'+
  327.                          '\n'+
  328.                          'CONST VERSION_DAY=\d\n'+
  329.                          'CONST VERSION_MONTH=\d\n'+
  330.                          'CONST VERSION_YEAR=\d\n'+
  331.                          '\n'+
  332.                          'CONST LIB_ID="\s"\n'+
  333.                          '\n'+
  334.                          '#define LIB_VERSION \a\d\a\n'+
  335.                          '#define LIB_REVISION \a\d\a\n'+
  336.                          '\n'+
  337.                          '#define LIB_NAME \a\s\a\n'+
  338.                          '#define LIB_FULL_NAME \axpk\s.library\a\n'+
  339.                          '#define LIB_DATE \a\s\a\n'+
  340.                          '#define LIB_VERSTR '+
  341.                          '\a$VER: xpk\s.library \d.\d (\s)\a\n'+
  342.                          '\n'+
  343.                          '#define VERSION_STRING {version_string}\n'+
  344.                          '#define VERSION_INFO {version_info}\n'+
  345.                          '\n'+
  346.                          'PROC dummy() IS NIL\n'+
  347.                          '\n'+
  348.                          'version_string:\n'+
  349.                          'CHAR \a$VER: \a\n'+
  350.                          'version_info:\n'+
  351.                          'CHAR \axpk\s.library \d.\d (\s)\a,0\n',
  352.                          name,
  353.                          version,
  354.                          revision,
  355.                          info_version,
  356.                          modes_version,
  357.                          version,
  358.                          revision,
  359.                          info_version,
  360.                          modes_version,
  361.                          day,
  362.                          month,
  363.                          year,
  364.                          name,      -> LIB_ID
  365.                          version,   -> LIB_VERSION
  366.                          revision,  -> LIB_REVISION
  367.                          name,      -> LIB_NAME
  368.                          name,      -> LIB_FULL_NAME
  369.                          datestr,   -> LIB_DATE
  370.                          name, version, revision, datestr,
  371.                          name, version, revision, datestr)
  372.     Fputs(bumpfh,bumpcontents)
  373.     Close(bumpfh)
  374.     PrintF('Done.\n')
  375.  
  376.  
  377. /*
  378. ** Compile bumpfile
  379. */
  380.  
  381.     IF donotcompile
  382.     ELSE
  383.       StringF(commandstring,'\s \s',ecpath,bumpfile)
  384.       Execute(commandstring,NIL,NIL)
  385.     ENDIF
  386.   ENDIF
  387.  
  388.  
  389.  
  390.  
  391. /*--------------------------  exceptions  ---------------------------*/
  392.  
  393.  
  394. EXCEPT
  395.   SELECT exception
  396.  
  397.     CASE ERR_ARGS
  398.       PrintFault(IoErr(),exefile)
  399.  
  400.     CASE ERR_NO_SOURCE
  401.       PrintF('Sourcefile \a\s\a not found...xpkrev did nothing.\n',sourcefile)
  402.  
  403.     CASE ERR_LAST_COMPILED
  404.       PrintF('Last revision still uncompiled...No need to bump.\n')
  405.  
  406.     CASE ERR_NO_BUMPFILE
  407.       PrintF('No bumpfile (_xpkrev.e) exists for \a\s\a...xpkrev did nothing.\n'+
  408.              'Set CREATE switch to create a bumpfile.\n',exefile)
  409.  
  410.     CASE ERR_BUMP_DELETE
  411.       PrintF('\nCouldn\at rewrite (delete) bumpfile. Remove delete protection.\n')
  412.  
  413.     CASE ERR_OPEN_BUMP_WRITE
  414.       PrintF('\n')
  415.       PrintFault(IoErr(),bumpfile)
  416.  
  417.   ENDSELECT
  418. ENDPROC
  419.